/*
 * @(#)SimulationApplet.java	06.09.1997  Robert Denda&Didier Gutacker
 *
 */

import java.awt.*;
import java.net.*;

/** 
 * Die Klasse SimulationApplet stellt den Ausgangspunkt der Simulation von Multicast 
 * und RIP-Routing Algorithmen dar, falls diese als Applet geschieht.  
 *
 * @author 	Robert Denda&Didier Gutacker
 * @version     1.1, 28.08.1997
 * @see ArchitectureComponent
 * @see Simulation
 * @see SimulationFrame
 * @see SimFrameRIP
 * @see SimFrameDVMRP
 */

/**
 *
 * Changes / Enhancements 
 *
 * 1) Added Buttons to open Simulations
 * 2) Added method oeffne_ripfenster to open SimFrameRIP
 * 3) Added method oeffne_dvmrpfenster to open SimFrameDVMRP
 *
 * Changes made by Didier Gutacker in August 1997
 *
 */

public class SimulationApplet extends java.applet.Applet implements Runnable, Simulation {

  private TextMethods text;	// the underlying text components (German or English)
  private ThreadGroup tg;	// the common thread group
  private Thread thread;	// dummy thread neede to create the common thread group

  private Button start_rip; // start Rip-Routing-Simulation-Button

  private Button start_dvmrp; // start Mbone-Simulation-Button

  private Lock textChangeGuard;	// synchronization of text component changes

  /**
   * Initialisierung
   */

  public void init() {
    textChangeGuard = new Lock();
    start_rip = new Button("RIP");
    add(start_rip);
    start_dvmrp = new Button("DVMRP");
    add(start_dvmrp);
  } // SimulationApplet.init

  /** 
   * Erzeugt den benotigten Thread
   */

  public void start() {
    text = new TextMethodsEnglishRIP();
    thread = new Thread( this );
    thread.start();
    tg = thread.getThreadGroup();
  } // SimulationApplet.start

  public void run() {
    thread.suspend();
  } // SimulationApplet.run

 /**
  * oeffnet RIP-Simulation
  * @see SimFrameRIP
  */

  public void oeffne_ripfenster()
  {
    SimFrameRIP f;
    text = new TextMethodsEnglishRIP();
    f = new SimFrameRIP( text, this );
    f.pack();
    f.resize(790,600);
    f.setBackground(Color.white);
    f.show();
   } // open Frame with Rip-Simulation

 /**
  * oeffnet DVMRP-Simulation
  * @see SimFrameDVMRP
  */

   public void oeffne_dvmrpfenster()
  {
    SimFrameDVMRP f;
    text = new TextMethodsEnglishDVMRP();
    f = new SimFrameDVMRP( text, this );
    f.pack();
    f.resize(790,600);
    f.setBackground(Color.white);
    f.show();
   } // open Frame with Dvmrp-Simulation

  /**
   * Liefert die gemeinsame Thread Gruppe
   */

  public ThreadGroup getThreadGroup() {
    return tg;
  } // SimulationApplet.getThreadGroup

  /**
   * Gibt den Text im Applet aus
   */

  public void paint( Graphics gc ) {
    // change font
    Font textFont = new Font("TimesRoman", Font.BOLD, 24 );
    gc.setFont( textFont );

    // draw String
     gc.drawString( text.beschreibung, 5, 95 );
    } // SimulationApplet.paint

  /**
   * Setzt die zugrundeliegende Sprache 
   * @see SimulationApplet#getText
   * @see TextMethodsDeutsch
   * @see TextMethodsEnglish
   */

  public void setText( TextMethods text ) {
    textChangeGuard.acquire();
    this.text = text;
    textChangeGuard.release();
    repaint();
  } // setText

  /**
   * Setzt die zugrundeliegende Sprache 
   * @see SimulationApplet#setText
   * @see TextMethodsDeutsch
   * @see TextMethodsEnglish
   */

  public TextMethods getText() {
    textChangeGuard.acquire();
    TextMethods returnValue = text;
    textChangeGuard.release();
    return returnValue;
  } // SimulationApplet.getText

  /**
   * Liefert das Bild, das fuer die Rechnersymbole verwendet wird
   * @see Knoten
   */

  public Image getRouterImage() {
    return getImage( getCodeBase(), "router.gif" );
  } // SimulationApplet.getCodeBase

  public boolean action(Event evt, Object arg)
   {
      if (arg.equals("RIP")) oeffne_ripfenster();
      else
         if (arg.equals("DVMRP")) oeffne_dvmrpfenster();
         else   
            return false;
      return true;
   } // 

} // SimulationApplet







